package cn.blt.security.auth.controller;


import cn.blt.security.auth.entity.SysUser;
import cn.blt.security.auth.entity.dto.UserDTO;
import cn.blt.security.auth.service.SysUserService;
import cn.blt.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 登录表 前端控制器
 * @author run
 * @since 2022-07-27
 */
@RestController
@RequestMapping("auth")
@Api(tags = "登录认证")
public class SysUserController   {

    @Resource
    private SysUserService userService;

    /**
     * 注册
     * @param user 用户
     * @return {@link Result}
     */
    @PostMapping("register")
    @ApiOperation("注册")
    public Result register(@RequestBody SysUser user) {
        return userService.register(user);
    }


    /**
     * 登录
     * @param user 用户
     * @return {@link Result}
     */
    @PostMapping("login")
    @ApiOperation("登录")
    public Result login(@RequestBody UserDTO user){
        return userService.login(user);
    }


    /**
     * 当前登录人信息
     * @param token 令牌
     * @return {@link Result}
     */
    @GetMapping("info")
    @ApiOperation("获取当前人得登录信息")
    public Result info(@RequestParam(value = "token") String token){
        return userService.info(token);
    }


    @PostMapping("logout")
    @ApiOperation("清除token")
    public Result logout(){
        return Result.ok();
    }


}
